//
//  YZNotificationSettingVC.m
//  VET
//
//  Created by 刘文靖 on 2018/6/29.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZNotificationSettingVC.h"
#import "YZGradientBtn.h"
#import "YZStateBtn.h"
#import "YZPersonalVM.h"
#import "YZUser.h"
@interface YZNotificationSettingVC ()
@property (weak, nonatomic) IBOutlet YZGradientBtn *confirmButton;
@property (weak, nonatomic) IBOutlet UISwitch *notificationStateButton;
@property (weak, nonatomic) IBOutlet UISwitch *detailStateButton;
@property (strong, nonatomic) YZPersonalVM *viewModel;

@end

@implementation YZNotificationSettingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"新消息通知";
    self.viewModel = [YZPersonalVM new];
    self.notificationStateButton.on = YES;
    self.detailStateButton.on = YES;
    YZUser *currentUser = [[[YZUser alloc] init] getLocalUser];
    for (NSDictionary *userPropertie in currentUser.userProperties) {
        if ([userPropertie[@"propertieKey"] isEqualToString:@"msg_notify"]) {
            self.notificationStateButton.on = [userPropertie[@"propertieVal"] integerValue];
        }else if ([userPropertie[@"propertieKey"] isEqualToString:@"msg_details"]){
             self.detailStateButton.on = [userPropertie[@"propertieVal"] integerValue];
        }
    }
}
- (IBAction)confirmBtnClicked {
    NSString *msg_notify = self.notificationStateButton.isOn?@"1":@"0";
    NSString *msg_details = self.detailStateButton.isOn?@"1":@"0";
    NSDictionary *params = @{@"userProperties":@[@{@"propertieKey":@"msg_notify",@"propertieVal":msg_notify},@{@"propertieKey":@"msg_details",@"propertieVal":msg_details}]};
    [[self.viewModel updteNotificationSetting:params] subscribeError:^(NSError * _Nullable error) {
        [SVProgressHUD yz_showError:@"网络异常"];
    } completed:^{
        [SVProgressHUD yz_showMessage:@"提交成功"];
        [self.navigationController popViewControllerAnimated:YES];

    }];
}

@end
